package com.kuqi.blog.controller;

import com.kuqi.blog.common.aop.LogAnnotation;
import com.kuqi.blog.dao.pojo.Article;
import com.kuqi.blog.service.ArticleService;
import com.kuqi.blog.vo.Result;
import com.kuqi.blog.vo.params.ArticleParam;
import com.kuqi.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:kuqi
 * @createTime:2021/12/5 16:14
 * @description:
 */
@RestController  //json格式进行数据交互
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 首页 文章列表
     * @param pageParams
     * @return
     */
    @PostMapping
    //加上此注解，代表要对此接口记录日志----->AOP日志，动态代理
    @LogAnnotation(module = "文章",operation = "获取文章列表")
    public Result listArticles(@RequestBody PageParams pageParams){
        return articleService.listArticles(pageParams);
    }

    /**
     * 首页的最热文章
     */
    @PostMapping("/hot")
    public Result hotArticle(){
        int limit = 5;
        return  articleService.hotArticle(limit);
    }

    /**
     * 首页的最新文档
     */
    @PostMapping("/new")
    public Result newArticles(){
        int limit = 5;
        return articleService.newArticles(limit);
    }


    /**
     * 文章归档
     */
    @PostMapping("/listArchives")
    public Result listArchives(){
        return articleService.listArchives();
    }


    /**
     * 文章详情接口
     */
    @PostMapping("/view/{id}")
    public Result findArticleById(@PathVariable("id") Long articleId){
        return articleService.findArticleById(articleId);
    }


    /**
     * 发布文章接口
     */
    @PostMapping("/publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        return articleService.publish(articleParam);
    }
}
